package com.ordermeals.activity;

import java.util.ArrayList;
import java.util.HashMap;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.GridView;
import android.widget.SimpleAdapter;

import com.ordermeals.R;
import com.ordermeals.util.Loger;

/***
 * 主界面
 * */
public class MainActivity extends Activity {
	/** Called when the activity is first created. */
	private static final String tag = MainActivity.class.getName();
	Button ydBtn;// 预定按钮
	Button saveOrderBtn;// 存单按钮
	Button selectOrderBtn;// 查单按钮
	Button orderBtn;// 点菜按钮
	Button exitBtn;// 注销按钮
	GridView baojianGird;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		ydBtn = (Button) findViewById(R.id.ydBtn);
		saveOrderBtn = (Button) findViewById(R.id.saveOrderBtn);
		orderBtn = (Button) findViewById(R.id.orderBtn);
		selectOrderBtn = (Button) findViewById(R.id.selectOrderBtn);
		baojianGird = (GridView) findViewById(R.id.baojianGird);
		initGird();
		ydBtn.setOnClickListener(ydBtntListener);
		saveOrderBtn.setOnClickListener(saveOrderBtnListener);
		orderBtn.setOnClickListener(orderBtnListener);
		selectOrderBtn.setOnClickListener(selectOrderBtnListener);
	}

	private void initGird() {
		Loger.d(tag, "initGird");
		ArrayList<HashMap<String, Object>> lstImageItem = new ArrayList<HashMap<String, Object>>();
		for (int i = 0; i < 80; i++) {
			HashMap<String, Object> map = new HashMap<String, Object>();
			//map.put("baojianImg", R.drawable.ic_launcher);// 添加图像资源的ID
			map.put("baojianNameText", "包间." + String.valueOf(i+1));// 按序号做ItemText
			lstImageItem.add(map);
		}
		SimpleAdapter saImageItems = new SimpleAdapter(this, // 没什么解释
				lstImageItem,// 数据来源
				R.layout.baojian_item,// night_item的XML实现

				// 动态数组与ImageItem对应的子项
				new String[] {  "baojianNameText" },

				// ImageItem的XML文件里面的一个ImageView,两个TextView ID
				new int[] { R.id.baojianNameText });
		
		baojianGird.setAdapter(saImageItems);  

	}

	OnClickListener ydBtntListener = new OnClickListener() {

		@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub
			Loger.d(tag, "ydBtntBtnListener");
			Intent intent = new Intent();
			intent.setClass(MainActivity.this, ScheduledActivity.class);
			startActivity(intent);
		}

	};

	OnClickListener saveOrderBtnListener = new OnClickListener() {

		@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub
			Loger.d(tag, "ydBtntBtnListener");
			Intent intent = new Intent();
			intent.setClass(MainActivity.this, SaveOrderActivity.class);
			startActivity(intent);
		}

	};
	OnClickListener selectOrderBtnListener = new OnClickListener() {

		@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub
			Loger.d(tag, "ydBtntBtnListener");
			Intent intent = new Intent();
			intent.setClass(MainActivity.this, SelectOrderActivity.class);
			startActivity(intent);
		}

	};
	OnClickListener orderBtnListener = new OnClickListener() {

		@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub
			Loger.d(tag, "ydBtntBtnListener");
			Intent intent = new Intent();
			intent.setClass(MainActivity.this, OrderActivity.class);
			startActivity(intent);
		}

	};
}